var API_HOST = "http://localhost:8888";
function wxRequest(action, method, params, successFun, errorFun) {
  console.log(API_HOST + action);
  wx.request({
    url: API_HOST + action,
    method: method ? method : 'GET',
    data: params,
    header: {
      // "Content-Type": "application/x-www-form-urlencoded",
      'content-type': 'application/json'
    },
    success: function (res) {
       console.log(JSON.stringify(res.data));
      successFun(res.data);
    },
    fail: function (error) {
      console.log(error);
      errorFun(error);
      //Modal.showModal('api ' + action, '请求失败:' + JSON.stringify(error));
    }
  })
}

function houseList(params, successFun, errorFun) {
  wxRequest('/house/list', 'GET', params, successFun, errorFun);
}
function houseDetails(params, successFun, errorFun){
  wxRequest('/house/details', 'GET', params, successFun, errorFun);
}
function imageUrl(params, successFun, errorFun) {
  wxRequest('/image/url', 'GET', params, successFun, errorFun);
}
function login(params, successFun, errorFun) {
  wxRequest('/user/login', 'GET', params, successFun, errorFun);
}
module.exports = {
  houseList: houseList,
  houseDetails: houseDetails,
  imageUrl: imageUrl,
  login: login
}
